use std::fmt::Display;

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug, PartialEq)]
pub enum Error {
    Internal(String),
}

/// 文件异常
impl From<std::io::Error> for Error {
    fn from(value: std::io::Error) -> Self {
        Error::Internal(value.to_string())
    }
}

/// 打印异常
impl Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            Error::Internal(err) => write!(f, "{}", err),
        }
    }
}

impl From<serde_json::Error> for Error {
    fn from(value: serde_json::Error) -> Self {
        Error::Internal(value.to_string())
    }
}

impl From<&str> for Error {
    fn from(value: &str) -> Self {
        Error::Internal(value.to_string())
    }
}

impl From<&String> for Error {
    fn from(value: &String) -> Self {
        Error::Internal(value.to_string())
    }
}